package com.hs.sfzy.service.impl;

import com.hs.sfzy.entity.ClassAnswer;
import com.hs.sfzy.entity.User;
import com.hs.sfzy.mapper.ClassAnswerMapper;
import com.hs.sfzy.mapper.UserMapper;
import com.hs.sfzy.service.ClassAnswerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName ClassAnswerServiceImpl
 * @Description TODO
 * @Author Chen
 * @Date 2025年08月13日 14:22
 * @Version 1.0
 */
@Service
public class ClassAnswerServiceImpl implements ClassAnswerService {
    @Autowired
    private ClassAnswerMapper classAnswerMapper;

    @Override
    public List<ClassAnswer> getClassAnswerByQuestionId(Integer questionId) {
        return classAnswerMapper.getClassAnswerByQuestionId(questionId);
    }

    @Override
    public List<ClassAnswer> getClassAnswerByUserId(Integer userId) {
        return classAnswerMapper.getClassAnswerByUserId(userId);
    }

    @Autowired
    private UserMapper userMapper;
    @Override
    public Integer addClassAnswer(ClassAnswer classAnswer) {
        User user = userMapper.findUserById(classAnswer.getUserId());
        user.setPoints(user.getPoints() + 10);
        userMapper.updateUser(user);
        return classAnswerMapper.addClassAnswer(classAnswer);
    }
}
